<template>
  <div style="margin-top:30px">
    <el-form ref="form" :model="form" label-width="80px" :rules="rules">
      <el-row>
        <el-col :span="24">
          <div class="grid-content bg-purple">
            <el-form-item label="容器编码" style="margin-right:15px" prop="barCode">
              <el-input v-model="form.barCode" placeholder="请输入容器编码" style="width:100%"  maxlength="100"  show-word-limit/>
            </el-form-item>
          </div>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <div class="grid-content bg-purple">
            <el-form-item label="容器类型" style="margin-right:15px" prop="type">
              <el-select v-model="form.type" placeholder="请输入容器类型" clearable style="width:100%">
                <el-option value="0" label="托盘"/>
                <el-option value="1" label="周转箱"/>
              </el-select>

            </el-form-item>
          </div>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <div class="grid-content bg-purple">
            <el-form-item label="备注" style="margin-right:15px" prop="remarks">
              <el-input v-model="form.remarks" placeholder="请输入备注" style="width:100%"  maxlength="100"  show-word-limit/>
            </el-form-item>
          </div>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="funcSubmit" :disabled="isDisable" plain>确 定</el-button>
    </div>
  </div>
</template>
<script>
import Vue from 'vue'
import 'xe-utils'
import VXETable from 'vxe-table'
import 'vxe-table/lib/index.css'
import request from '@/utils/request'
import { containerAdd} from '@/api/basicInfo'

Vue.use(VXETable)
export default {
  data() {
    return {
        isDisable:false,   //确定键显示按钮

      form: {
        barCode:'',              //容器条码 ,
        code:'',                      //数据标识 ,
        type:'',                      //名称 ,
        remarks:'',                   //备注 ,
        shipmentCode:'',              //所属入驻商 ,

      },
        rules: {
          barCode: [
            {required: true, message: '请输入容器编码', trigger: 'blur'},
              { min: 1, max: 100, message: '容器编码长度不能大于100', trigger: 'blur' }
          ],
          type: [
            {required: true, message: '请输入容器类型', trigger: 'blur'},
          ],
        },
    }
  },
  created() {
  },
  methods: {
    // 重置
    reset(){
      this.$refs['form'].resetFields()
    },
    // 提交
    funcSubmit() {
      const data = this.form
      this.$refs['form'].validate((valid) => {
        if (valid) {
          this.isDisable = true
          containerAdd(data).then(response => {
            this.$message({ message: response.msg, type: 'success' })
            this.$emit('fatherAddMethod')
            //this.form = {}
          }).catch(() => this.isDisable = false)
          .finally(()=>{
            this.isDisable = false
          })
        } else {
          return false
        }
      })
    },
    // 取消
    funcCancel() {
      this.$emit('fatherCancelMethod', 'add')
    }
  }
}
</script>
<style lang="scss" scoped >
  .dialog-footer {
    margin: 15px 0 15px 0;
    width: 90px;
    float: right;
  }
</style>
